<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>解决click与onmousedown和onmouseup之间的冲突</title>
</head>
<body>

<script>
    //当点击鼠标时长大于0.3秒执行拖拽，当点击时长小于0.3秒跳转
    var firstTime = 0;
    var lastTime = 0;
    var key = false;
    document.onmousedown = function () {
        firstTime = new Date().getTime();
    };
    document.onmouseup = function () {
        lastTime = new Date().getTime();
        if(lastTime - firstTime < 1000){
            key = true;
        }else {
            console.log("drag");
        }

    };
    document.onclick = function () {
        if(key){
            console.log("click")
            key = false;
        }
    }
</script>

</body>
</html>
